hint("请绑定水机");
//微信借口配置
function configfn(){
	wx.config({
	    debug:false,
	    appId:$('.appId_val').val(),
	    timestamp:$('.timestamp_val').val(),
	    nonceStr:$('.nonceStr_val').val(),
	    signature:$('.signature_val').val(),
	    jsApiList:['scanQRCode']
	});
}

//微信扫一扫
function saoyisao(){
	$("#scan").click(function(){
	  	wx.scanQRCode({
		    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		    scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
		    success: function (res) {
			    if (res.errMsg === "scanQRCode:ok"){
				    $.ajax({
				    	url:"/api/device/bind",
				    	type:"post",
				    	data:{device_code:res.resultStr},
				    	dataType:'json',
				    	success:function(data){
				    		if(data.status.errCode == 0||data.status.errCode == 20002){
				    			hint("绑定成功!");
		    					setTimeout(function(){
		    						window.location.href = "/index?"+new Date().getTime();
		    					},300);
				    		}else{					    			
				    			hint(data.status.message);
				    		}
				    	},
				    	error:function(jqXHR, textStatus, errorThrown){
		    				hint("绑定失败" + jqXHR.status + textStatus + errorThrown);
				    		//console.log(jqXHR.status);
				    	}
				    });
			    }
			}
		});
    });
}
    
